<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { useTranslationLang } from "@/layout/hooks/useTranslationLang";
const { locale } = useTranslationLang();
import { useI18n } from "vue-i18n";
const { t } = useI18n();

const props = withDefaults(defineProps<FormProps>(), {
    formInline: () => ({
        startLocId: null,
        endLocId: null,
        agvId: null,
        batch: "",
        locState: 0,
        emptyTray: 0,
        outTaskCode: null,
        trayCode: null,
    }),
    formCargo: [],
    agvSelect: []
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
const formCargo = ref(props.formCargo);
const agvSelect = ref(props.agvSelect);

const selectOptions = {
    filterable: true,
    clearable: true,
    placeholder: t("job.selectCargoLocation"),
    options: formCargo.value.map(item => ({
        value: item.Id,
        label: item.Code
    }))
};

function getRef() {
    return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
    <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="110px"
        :label-position="locale === 'en' ? 'top' : 'right'">
        <el-row :gutter="30">
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('job.startLocation')" prop="startLocId">
                    <!-- <el-select v-model="newFormInline.startLocId" filterable clearable style="width:100%">
                        <el-option v-for="item in formCargo" :key="item.Code" :label="item.Code" :value="item.Id" />
                    </el-select> -->
                    <vxe-select v-model="newFormInline.startLocId" v-bind="selectOptions"></vxe-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('job.endLocation')" prop="endLocId">
                    <!-- <el-select v-model="newFormInline.endLocId" filterable clearable style="width:100%">
                        <el-option v-for="item in formCargo" :key="item.Code" :label="item.Code" :value="item.Id" />
                    </el-select> -->
                    <vxe-select v-model="newFormInline.endLocId" v-bind="selectOptions"></vxe-select>
                </el-form-item>
            </re-col>

            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('job.locationStatus')" prop="locState">
                    <el-switch v-model="newFormInline.locState" width="60"
                        style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" inline-prompt
                        :active-value="1" :inactive-value="0" :active-text="t('job.enable')"
                        :inactive-text="t('job.disable')" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('job.supplementEmptyTrays')" prop="emptyTray">
                    <el-switch v-model="newFormInline.emptyTray" width="60"
                        style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" inline-prompt
                        :active-value="1" :inactive-value="0" :active-text="t('job.yes')"
                        :inactive-text="t('job.no')" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('job.vehicle')" prop="agvId">
                    <el-select v-model="newFormInline.agvId" filterable clearable style="width:100%">
                        <el-option v-for="item in agvSelect" :key="item.AgvId" :label="item.AgvName"
                            :value="item.AgvId">
                        </el-option>
                    </el-select>
                </el-form-item>
            </re-col>
            <!-- <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="batch" prop="batch">
          <el-input v-model="newFormInline.batch" clearable placeholder="请输入batch" />
        </el-form-item>
      </re-col> -->
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('job.thirdPartyTaskCode')" prop="outTaskCode">
                    <el-input v-model="newFormInline.outTaskCode" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('job.trayCode')" prop="trayCode">
                    <el-input v-model="newFormInline.trayCode" clearable />
                </el-form-item>
            </re-col>
        </el-row>
    </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
    margin-right: 16px;
}
</style>
